/* Reset and Base Styles */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Common Variables */
:root {
    /* Colors */
    --color-primary: #007bff;
    --color-secondary: #6c757d;
    --color-success: #28a745;
    --color-danger: #dc3545;
    --color-warning: #ffc107;
    --color-info: #17a2b8;
    --color-light: #f8f9fa;
    --color-dark: #343a40;
    --color-white: #ffffff;
    --color-black: #000000;

    /* Focus and Interaction */
    --focus-outline-color: #005fcc;
    --focus-outline-width: 2px;
    --focus-outline-offset: 2px;
    --transition-speed: 0.3s;

    /* Typography */
    --font-primary: Arial, sans-serif;
    --font-secondary: 'Helvetica Neue', Helvetica, sans-serif;
    --font-size-base: 16px;
    --line-height-base: 1.5;

    /* Container Widths */
    --container-4k: 2560px;
    --container-desktop: 1200px;
    --container-tablet: 960px;
    --container-mobile: 720px;
    --container-small: 540px;

    /* Spacing */
    --spacing-xs: 5px;
    --spacing-sm: 10px;
    --spacing-md: 15px;
    --spacing-lg: 20px;
    --spacing-xl: 30px;

    /* Header Heights */
    --header-height-4k: 120px;
    --header-height-desktop: 80px;
    --header-height-tablet: 70px;
    --header-height-mobile: 60px;
    --header-height-small: 50px;

    /* Z-indices */
    --z-index-header: 1000;
    --z-index-dropdown: 1010;
}

/* Base Styles with Accessibility Considerations */
html {
    font-size: var(--font-size-base);
    line-height: var(--line-height-base);
    -webkit-text-size-adjust: 100%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    scroll-behavior: smooth;
}

body {
    margin: 0;
    padding: 0;
    font-family: var(--font-primary);
    line-height: var(--line-height-base);
    color: var(--color-dark);
    background-color: var(--color-white);
    min-height: 100vh;
    text-rendering: optimizeSpeed;
}

/* Global Focus Styles */
:focus {
    outline: var(--focus-outline-width) solid var(--focus-outline-color);
    outline-offset: var(--focus-outline-offset);
}

:focus:not(:focus-visible) {
    outline: none;
}

:focus-visible {
    outline: var(--focus-outline-width) solid var(--focus-outline-color);
    outline-offset: var(--focus-outline-offset);
}

/* Skip Link - Hidden until focused */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--color-primary);
    color: var(--color-white);
    padding: 8px;
    z-index: calc(var(--z-index-header) + 1);
    transition: top 0.2s ease;
}

.skip-link:focus {
    top: 0;
}

/* Container Class */
.alpi-cms-content-container {
    width: 100%;
    margin-left: auto;
    margin-right: auto;
    padding-left: var(--spacing-md);
    padding-right: var(--spacing-md);
}

/* Utility Classes */
.visually-hidden:not(:focus):not(:active) {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

.clearfix::after {
    content: "";
    display: table;
    clear: both;
}

/* Image Handling */
img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* Default Link Styles */
a {
    color: var(--color-primary);
    text-decoration: none;
    transition: color var(--transition-speed) ease;
}

a:hover {
    text-decoration: underline;
}

/* Button Reset */
button {
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    font-family: inherit;
    font-size: inherit;
    color: inherit;
}

/* Header Styles */
.header-wrap {
    position: sticky;
    top: 0;
    width: 100%;
    background-color: var(--color-white);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    z-index: var(--z-index-header);
    padding: 0 24px;
    height: var(--header-height-desktop);
    display: flex;
    align-items: center;
    gap: 20px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

/* Logo and Title */
.header-wrap h1 {
    margin: 0;
    font-size: 24px;
    font-weight: 600;
    color: var(--color-dark);
    white-space: nowrap;
    flex-shrink: 0;
}

.site-logo {
    height: 40px;
    width: auto;
    object-fit: contain;
}

/* Logo Accessibility - Broken Image Handling */
.site-logo:not([src]),
.site-logo[src=""],
.site-logo[src="#"] {
    visibility: hidden;
    position: relative;
}

.site-logo:not([src])::after,
.site-logo[src=""]::after,
.site-logo[src="#"]::after {
    visibility: visible;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--color-light);
    border: 1px solid var(--color-secondary);
    content: attr(alt);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 5px;
    font-size: 12px;
    text-align: center;
    color: var(--color-dark);
}

/* Navigation Container */
.header-menu-container {
    position: relative;
    height: 100%;
    display: flex;
    align-items: center;
}

/* Navigation Button */
.header-menu-container>button {
    padding: 8px 16px;
    background-color: var(--color-light);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 6px;
    color: var(--color-dark);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-speed) ease;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    position: relative;
}

/* Button Arrow Indicator */
.header-menu-container>button:after {
    content: '';
    width: 8px;
    height: 8px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg) translateY(-2px);
    transition: transform var(--transition-speed) ease;
}

/* Button States */
.header-menu-container>button:hover {
    background-color: #e9ecef;
}

.header-menu-container>button:focus-visible {
    outline: var(--focus-outline-width) solid var(--focus-outline-color);
    outline-offset: var(--focus-outline-offset);
}

.header-menu-container:hover>button:after {
    transform: rotate(-135deg) translateX(-2px);
}

/* Dropdown Menu */
.header-dropdown-content {
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 220px;
    background-color: var(--color-white);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: all var(--transition-speed) ease;
    padding: 8px 0;
    margin-top: 4px;
    z-index: var(--z-index-dropdown);
}

/* Dropdown Visibility */
.header-menu-container:hover .header-dropdown-content,
.header-menu-container:focus-within .header-dropdown-content {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* Dropdown Links */
.header-dropdown-content a {
    color: var(--color-dark);
    padding: 10px 16px;
    text-decoration: none;
    display: block;
    font-size: 14px;
    transition: background-color var(--transition-speed) ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Dropdown Link States */
.header-dropdown-content a:hover {
    background-color: var(--color-light);
    text-decoration: none;
}

.header-dropdown-content a:focus {
    outline: none;
    background-color: var(--color-light);
    text-decoration: none;
}

.header-dropdown-content a:focus-visible {
    outline-offset: -2px;
}

/* Current Page Indicator */
.header-dropdown-content a[aria-current="page"] {
    font-weight: 600;
    background-color: rgba(0, 123, 255, 0.1);
}

/* Touch Device Optimizations */
@media (hover: none) {
    .header-menu-container>button {
        padding-right: 24px;
        /* Increased touch target */
    }

    .header-dropdown-content a {
        padding: 12px 16px;
        /* Increased touch target */
    }
}

/* Responsive Breakpoints */

/* 4K and larger screens (≥2560px) */
@media screen and (min-width: 2560px) {
    .alpi-cms-content-container {
        max-width: var(--container-4k);
    }

    .header-wrap {
        height: var(--header-height-4k);
        padding: 0 48px;
    }

    .header-wrap h1 {
        font-size: 36px;
    }

    .site-logo {
        height: 60px;
    }

    .header-menu-container>button {
        padding: 12px 24px;
        font-size: 18px;
    }

    .header-menu-container>button:after {
        width: 10px;
        height: 10px;
        border-width: 3px;
    }

    .header-dropdown-content {
        min-width: 300px;
        margin-top: 6px;
        border-radius: 12px;
    }

    .header-dropdown-content a {
        padding: 14px 24px;
        font-size: 16px;
    }
}

/* Desktop screens (1200px to 2559px) */
@media screen and (min-width: 1200px) and (max-width: 2559px) {
    .alpi-cms-content-container {
        max-width: var(--container-desktop);
    }

    /* Default styles already set in base CSS */
}

/* Tablet screens (768px to 1199px) */
@media screen and (min-width: 768px) and (max-width: 1199px) {
    .alpi-cms-content-container {
        max-width: var(--container-tablet);
    }

    .header-wrap {
        height: var(--header-height-tablet);
        padding: 0 20px;
        gap: 15px;
    }

    .header-wrap h1 {
        font-size: 20px;
    }

    .site-logo {
        height: 36px;
    }

    .header-menu-container>button {
        padding: 6px 12px;
        font-size: 13px;
    }

    .header-menu-container>button:after {
        width: 7px;
        height: 7px;
        border-width: 2px;
    }

    .header-dropdown-content {
        min-width: 200px;
        margin-top: 4px;
    }

    .header-dropdown-content a {
        padding: 8px 16px;
        font-size: 13px;
    }
}

/* Mobile screens (481px to 767px) */
@media screen and (min-width: 481px) and (max-width: 767px) {
    .alpi-cms-content-container {
        max-width: var(--container-mobile);
        padding-left: var(--spacing-sm);
        padding-right: var(--spacing-sm);
    }

    .header-wrap {
        height: var(--header-height-mobile);
        padding: 0 16px;
        gap: 10px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .header-wrap::-webkit-scrollbar {
        display: none;
    }

    .header-wrap h1 {
        font-size: 18px;
    }

    .site-logo {
        height: 32px;
    }

    .header-menu-container>button {
        padding: 5px 10px;
        font-size: 12px;
        white-space: nowrap;
    }

    .header-menu-container>button:after {
        width: 6px;
        height: 6px;
        border-width: 2px;
    }

    .header-dropdown-content {
        min-width: 180px;
        /* Ensure dropdown doesn't go off-screen */
        left: 50%;
        transform: translateX(-50%) translateY(10px);
    }

    .header-menu-container:hover .header-dropdown-content,
    .header-menu-container:focus-within .header-dropdown-content {
        transform: translateX(-50%) translateY(0);
    }

    .header-dropdown-content a {
        padding: 8px 12px;
        font-size: 12px;
    }
}

/* Small mobile screens (≤480px) */
@media screen and (max-width: 480px) {
    .alpi-cms-content-container {
        max-width: var(--container-small);
        padding-left: var(--spacing-xs);
        padding-right: var(--spacing-xs);
    }

    .header-wrap {
        height: var(--header-height-small);
        padding: 0 12px;
        gap: 8px;
        overflow-x: auto;
        scrollbar-width: none;
        -ms-overflow-style: none;
        -webkit-overflow-scrolling: touch;
    }

    .header-wrap h1 {
        font-size: 16px;
        max-width: 150px;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .site-logo {
        height: 28px;
    }

    .header-menu-container>button {
        padding: 4px 8px;
        font-size: 11px;
        min-height: 32px;
        /* Ensure minimum touch target size */
    }

    .header-menu-container>button:after {
        width: 5px;
        height: 5px;
        border-width: 1.5px;
    }

    .header-dropdown-content {
        min-width: 160px;
        left: 50%;
        transform: translateX(-50%) translateY(10px);
        max-height: 60vh;
        /* Prevent overflow on small screens */
        overflow-y: auto;
    }

    .header-menu-container:hover .header-dropdown-content,
    .header-menu-container:focus-within .header-dropdown-content {
        transform: translateX(-50%) translateY(0);
    }

    .header-dropdown-content a {
        padding: 10px 12px;
        /* Increased touch target */
        font-size: 11px;
        min-height: 44px;
        /* Ensure minimum touch target size */
        display: flex;
        align-items: center;
    }
}

/* Accessibility Enhancements */

/* Reduced Motion Preferences */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }

    html {
        scroll-behavior: auto;
    }

    .header-menu-container>button,
    .header-menu-container>button:after,
    .header-dropdown-content,
    .header-dropdown-content a {
        transition: none !important;
    }

    /* Remove transform animations */
    .header-dropdown-content {
        transform: none !important;
    }

    .header-menu-container:hover .header-dropdown-content,
    .header-menu-container:focus-within .header-dropdown-content {
        transform: none !important;
    }
}

/* High Contrast Mode */
@media (forced-colors: active) {
    .header-wrap {
        border-bottom: 1px solid ButtonBorder;
        background-color: Canvas;
        forced-color-adjust: none;
    }

    .site-logo {
        forced-color-adjust: auto;
    }

    .header-menu-container>button {
        border: 1px solid ButtonBorder;
        background-color: ButtonFace;
        color: ButtonText;
        forced-color-adjust: none;
    }

    .header-menu-container>button:hover,
    .header-menu-container>button:focus {
        border-color: Highlight;
        background-color: ButtonFace;
        color: Highlight;
    }

    .header-menu-container>button:after {
        border-color: currentColor;
    }

    .header-dropdown-content {
        border: 1px solid ButtonBorder;
        background-color: Canvas;
        box-shadow: none;
    }

    .header-dropdown-content a {
        color: ButtonText;
        forced-color-adjust: none;
    }

    .header-dropdown-content a:hover,
    .header-dropdown-content a:focus {
        background-color: Highlight;
        color: HighlightText;
    }

    .header-dropdown-content a[aria-current="page"] {
        border: 1px solid ButtonBorder;
    }
}

/* Increased Color Contrast */
@media (prefers-contrast: more) {
    :root {
        --color-primary: #0056b3;
        --focus-outline-color: #003d80;
    }

    .header-wrap {
        box-shadow: none;
        border-bottom: 2px solid var(--color-dark);
    }

    .header-menu-container>button {
        border: 2px solid currentColor;
        background-color: var(--color-white);
    }

    .header-dropdown-content {
        border: 2px solid var(--color-dark);
        box-shadow: none;
    }

    .header-dropdown-content a {
        border-bottom: 1px solid rgba(0, 0, 0, 0.2);
    }

    .header-dropdown-content a:last-child {
        border-bottom: none;
    }

    /* Increase contrast for current page indicator */
    .header-dropdown-content a[aria-current="page"] {
        background-color: var(--color-primary);
        color: var(--color-white);
    }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    :root {
        --color-dark: #f8f9fa;
        --color-light: #343a40;
        --color-white: #212529;
        --color-black: #ffffff;
    }

    .header-wrap {
        background-color: #1a1a1a;
        border-bottom-color: rgba(255, 255, 255, 0.1);
    }

    .header-menu-container>button {
        background-color: #2d2d2d;
        border-color: rgba(255, 255, 255, 0.1);
    }

    .header-dropdown-content {
        background-color: #1a1a1a;
        border-color: rgba(255, 255, 255, 0.1);
    }

    .header-dropdown-content a:hover,
    .header-dropdown-content a:focus {
        background-color: #2d2d2d;
    }
}

/* Print Styles */
@media print {

    /* General print optimizations */
    * {
        background: transparent !important;
        color: #000 !important;
        box-shadow: none !important;
        text-shadow: none !important;
        transition: none !important;
    }

    .header-wrap {
        position: static;
        height: auto;
        padding: 15px 0;
        border-bottom: 1pt solid #000;
        margin-bottom: 20px;
    }

    /* Hide unnecessary elements */
    .header-menu-container,
    .skip-link {
        display: none !important;
    }

    /* Logo and title optimization */
    .site-logo {
        height: 30px;
        print-color-adjust: exact;
        -webkit-print-color-adjust: exact;
    }

    .header-wrap h1 {
        font-size: 18pt;
        margin: 0;
    }

    /* Container adjustments */
    .alpi-cms-content-container {
        max-width: none;
        padding: 0;
        margin: 0;
    }

    /* Add URL after links */
    a[href]:after {
        content: " (" attr(href) ")";
        font-size: 90%;
    }

    /* Don't show URL for same-page links */
    a[href^="#"]:after {
        content: "";
    }
}